package it.enricod.jcontextfree.jfx.control;

/**
 * @author enrico
 */

import javafx.animation.*;
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.text.*;
import javafx.stage.*;
import it.enricod.jcontextfree.engine.model.IFigure;
import it.enricod.jcontextfree.engine.model.FigureEnum;
import javafx.scene.transform.Transform;

public class PaintNode extends CustomNode {

    public var figures: IFigure[];
    public var nodes: Node[];

    override protected function create() : Node {

        for (fig in figures) {
            var node: Node = createNode(fig);
            insert node into nodes;
        };

        Group {
            content: [
                nodes
            ]
            }
    }

    function createNode(fig: IFigure): Node {
        if ( fig.getType().equals( FigureEnum.CIRCLE)) {
            return createCircleNode(fig);
        } else
        if ( fig.getType().equals(FigureEnum.SQUARE) ) {
            return createSquareNode(fig);
        }
        return null;
    }

    function createCircleNode(fig: IFigure) {
        var r: Number = fig.getParameters().getSize()/2;
        return Circle {
            centerX: fig.getFigureArea().getP1().getX() + r,
            centerY: fig.getFigureArea().getP1().getY() + r
            radius: r
            fill: Color.BLACK
        }
    }

    function createSquareNode(fig: IFigure) {
        return Rectangle {
            x: fig.getFigureArea().getP1().getX(),
            y: fig.getFigureArea().getP1().getY(),
            width: fig.getParameters().getSize(),
            height: fig.getParameters().getSize()
            fill: Color.BLACK
        }
    }


}
